package com.chixing.day15.day15_Home;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;


public class CalaChar {
    public static void main(String[] args) {
        File fir = new File("//Users//jasonmarslyon//CX_Workspace//Java_Workspace//Test//calcCharNum.txt");
        try {
            FileInputStream fis = new FileInputStream(fir);
            Map<Character,Integer> map = new HashMap<>();
            int num = 0;
            while((num = fis.read()) != -1) { //一个字节一个字节的读取fis文件直到结束,返回-1
                if((num >= 65 && num <= 90) || (num >= 97 && num <= 122)){
                    if(map.containsKey((char)num)){
                        map.put((char)num, map.get((char)num)+1);
                    }else{
                        map.put((char)num, 1);
                    }
                }
            }
            fis.close();
            Iterator it = map.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry entry = (Map.Entry) it.next();
                System.out.println(entry.getKey() + "(" + entry.getValue() + ")");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
